package com.dy.design_pattern_study.observer_mode.dome2_decoupling.notifier_code.impl;

import com.dy.design_pattern_study.observer_mode.dome1_coupling.StockObserver;
import com.dy.design_pattern_study.observer_mode.dome2_decoupling.notifier_code.Subject;
import com.dy.design_pattern_study.observer_mode.dome2_decoupling.observer_code.Observer;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-03
 * @Content
 */
@Data
public class Boss implements Subject {

    private List<Observer> observers = new ArrayList<>();

    //前台状态
    private String action;

    @Override
    public void Attach(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void Detach(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void Notify() {
        for (Observer observer : observers) {
            observer.Update();
        }
    }

    @Override
    public String sendMsg() {
        return getAction();
    }
}
